package org.bambrikii.kbManager.kb2.managers.query4.impl.builders;

import org.bambrikii.kbManager.kb2.managers.query4.And;
import org.bambrikii.kbManager.kb2.managers.query4.ConditionType;
import org.bambrikii.kbManager.kb2.managers.query4.ICondition;
import org.bambrikii.kbManager.kb2.managers.query4.In;
import org.bambrikii.kbManager.kb2.managers.query4.Like;
import org.bambrikii.kbManager.kb2.managers.query4.Or;

public abstract class QueryBuilderBase<T> {

	private ICondition<T> where;

	protected ICondition<T> getWhere() {
		return where;
	}

	public ICondition<T> where(ICondition<T> condition) {
		condition.setParent(null);
		this.where = condition;
		return this.where;
	}

	public ICondition<T> and(ConditionType type, ICondition<T>... conditions) {
		ICondition<T> condition = buildAnd(type, conditions);
		for (ICondition<T> condition1 : conditions) {
			condition1.setParent(condition);
		}
		return condition;
	}

	public ICondition<T> or(ConditionType type, ICondition<T>... conditions) {
		ICondition<T> condition = buildOr(type, conditions);
		for (ICondition<T> condition1 : conditions) {
			condition1.setParent(condition);
		}
		return condition;
	}

	public ICondition<T> like(ConditionType type, String value) {
		return buildLike(type, value);
	}

	public ICondition<T> in(ConditionType type, ICondition<T> condition1) {
		ICondition<T> condition = buildIn(type, condition1);
		condition1.setParent(condition);
		return condition;
	}

	protected abstract And<T> buildAnd(ConditionType type,
			ICondition<T>... conditions);

	protected abstract Or<T> buildOr(ConditionType type,
			ICondition<T>... conditions);

	protected abstract Like<T> buildLike(ConditionType type, String value);

	protected abstract In<T> buildIn(ConditionType type,
			ICondition<T> condition1);

	public abstract T build();
}
